﻿//编辑角色表
EditSys_Roles = function(id) {
    var EditSys_RolesForm = Ext.create("Ext.form.Panel", {
        width: 360,
        height: 450,
        autoScroll: true,
       
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 55,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right',  msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [{
            name: "RoleID",
            fieldLabel: "<font color='red'>*</font>角色ID自动ID",
            allowBlank: false,
            xtype: "hiddenfield",
            blankText: "角色ID自动ID不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "R_UserID",
            fieldLabel: "<font color='red'>*</font>角角所属用户ID",
            allowBlank: false,
            xtype: "hiddenfield",
            blankText: "角角所属用户ID不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "R_RoleName",
            fieldLabel: "<font color='red'>*</font>角色名称",
            allowBlank: false,
            blankText: "角色名称不能为空",
            regex: /^[\S]{1,50}$/,
            regexText: "请填写1～50个数字或字母"
        }, {
            name: "R_Description",
            fieldLabel: "角色介绍",
            regex: /^[\S]{0,255}$/,
            regexText: "请填写0～255个数字或字母"
        }
			]
    });

    var EditSys_RolesWin = new Ext.Window({
        title: "修改角色表",
        width: 400,
        id: "EditSys_RolesWin",
        height: 450,
        closeAction: 'destroy',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [EditSys_RolesForm],
        listeners: {
            "show": function() {
                if (id && id != "") {
                    //加载表单数据
                    EditSys_RolesForm.form.load(
                                {
                                    url: "/Manager/Sys_Roles/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {

                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }
        },
        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                //alert(EditSys_RolesForm.getForm().isValid())
                if (EditSys_RolesForm.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    EditSys_RolesForm.form.submit({
                        url: "/Manager/Sys_Roles/Update/" + id,
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                            Ext.MessageBox.hide();
                            var flag = action.result.success;
                            if (flag == "true") {
                                Sys_RolesStore.loadPage(1);
                               Ext.helper.msg("恭喜", "修改成功!");
                                EditSys_RolesWin.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("修改失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "修改失败!");
                                    EditSys_RolesWin.hide();
                                }

                            }
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                            EditSys_RolesWin.hide();
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function() {
                //加载表单数据
                EditSys_RolesForm.getForm().reset();
                EditSys_RolesForm.form.load(
                                {
                                    url: "/Manager/Sys_Roles/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {
                                    },
                                    failure: function(form, action) {
                                        //Ext.Msg.alert("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                EditSys_RolesWin.destroy();
            }

}]

        });

        EditSys_RolesWin.show();
        keyNav();
    }
